/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package digitaldreamers.libraries.games.servers.databasemanagement.concrete;

import digitaldreamers.libraries.games.servers.databasemanagement.abstracts.IDatabaseUtility;
import digitaldreamers.libraries.games.servers.databasemanagement.concrete.SqlParameter.ParameterDirection;
import digitaldreamers.libraries.games.servers.databasemanagement.concrete.SqlParameter.SqlDataType;
import digitaldreamers.libraries.games.servers.databasemanagement.concrete.mysql.MySqlDatabaseUtility;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author DaoLe
 */
public class DatabaseManagement implements IDatabaseUtility {
    // <editor-fold defaultstate="collapsed" desc="Supported DBMS enum">
    public static enum DbmsType {
        MySql
    }
    
    // <editor-fold defaultstate="collapsed" desc="Isolation level enum">
    public static enum IsolationLevel {
        TRANSACTION_READ_COMMITTED,
        TRANSACTION_READ_UNCOMMITTED,
        TRANSACTION_NONE,
        TRANSACTION_REPEATABLE_READ,
        TRANSACTION_SERIALIZABLE
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Members">
    private IDatabaseUtility mDatabaseUtility;
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Getters/Setters">
    @Override
    public String getServerName() {
        return mDatabaseUtility.getServerName();
    }
    

    @Override
    public void setServerName(String pServerName) {
        mDatabaseUtility.setServerName(pServerName);
    }

    @Override
    public int getPort() {
        return mDatabaseUtility.getPort();
    }

    @Override
    public void setPort(int pPort) {
        mDatabaseUtility.setPort(pPort);
    }

    @Override
    public String getDatabaseName() {
        return mDatabaseUtility.getDatabaseName();
    }

    @Override
    public void setDatabaseName(String pDatabaseName) {
        mDatabaseUtility.setDatabaseName(pDatabaseName);
    }
    
    @Override
    public String getUsername() {
        return mDatabaseUtility.getUsername();
    }

    @Override
    public void setUsername(String pUsername) {
        mDatabaseUtility.setUsername(pUsername);
    }

    @Override
    public String getPassword() {
        return mDatabaseUtility.getPassword();
    }

    @Override
    public void setPassword(String pPassword) {
        mDatabaseUtility.setPassword(pPassword);
    }
    
    @Override
    public int getCommandTimeout() {
        return mDatabaseUtility.getCommandTimeout();
    }

    @Override
    public void setCommandTimeout(int pCommandTimeout) {
        mDatabaseUtility.setCommandTimeout(pCommandTimeout);
    }
    // </editor-fold>
    
    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public DatabaseManagement(DbmsType pDbmsType) {
        switch(pDbmsType) {
            case MySql:
                mDatabaseUtility = new MySqlDatabaseUtility();
                break;
            default:
                mDatabaseUtility = new MySqlDatabaseUtility();
                break;
        }
    }
    
    public DatabaseManagement(DbmsType pDbmsType, String pServerName, int pPort, String pDatabaseName, String pUsername, String pPassword, int pCommandTimeout) {
        switch(pDbmsType) {
            case MySql:
                mDatabaseUtility = new MySqlDatabaseUtility(pServerName, pPort, pDatabaseName, pUsername, pPassword, pCommandTimeout);
                break;
            default:
                mDatabaseUtility = new MySqlDatabaseUtility(pServerName, pPort, pDatabaseName, pUsername, pPassword, pCommandTimeout);
                break;
        }
    }
    
    // <editor-fold defaultstate="collapsed" desc="Static Methods">
    public static SqlParameter createParameter(String pParameterName, ParameterDirection pDirection, SqlDataType pSqlDataType, Object pValue) throws IllegalArgumentException {
        return new SqlParameter(pParameterName, pDirection, pSqlDataType, pValue);
    }
    
    // <editor-fold defaultstate="collapsed" desc="Methods">
    @Override
    public void closeOnCompletion(boolean bIsCloseOnCompletion) {
        mDatabaseUtility.closeOnCompletion(bIsCloseOnCompletion);
    }
    
    @Override
    public boolean isCloseOnCompletion() {
        return mDatabaseUtility.isCloseOnCompletion();
    }
    
    @Override
    public boolean isTransactionStarted() {
        return mDatabaseUtility.isTransactionStarted();
    }
    
    @Override
     public ResultSet executeQuery(String pSqlStatement) throws SQLException {
         return mDatabaseUtility.executeQuery(pSqlStatement);
     }
    
    @Override
    public ResultSet executeQuery(String pSqlStatement, SqlParameter[] pParameters) throws SQLException {
        return mDatabaseUtility.executeQuery(pSqlStatement, pParameters);
    }
    
    @Override
    public int executeUpdate(String pSqlStatement) throws SQLException {
        return mDatabaseUtility.executeUpdate(pSqlStatement);
    }
    
    @Override
    public int executeUpdate(String pSqlStatement, SqlParameter[] pParameters) throws SQLException {
        return mDatabaseUtility.executeUpdate(pSqlStatement, pParameters);
    }
    
    @Override
    public ResultSet executeQuerySP(String pStoredProcedureName) throws SQLException {
        return mDatabaseUtility.executeQuerySP(pStoredProcedureName);
    }
    
    @Override
    public ResultSet executeQuerySP(String pStoredProcedureName, SqlParameter[] pParameters) throws SQLException {
        return mDatabaseUtility.executeQuerySP(pStoredProcedureName, pParameters);
    }
    
    @Override
    public int executeUpdateSP(String pStoredProcedureName) throws SQLException {
        return mDatabaseUtility.executeUpdateSP(pStoredProcedureName);
    }
    
    @Override
    public int executeUpdateSP(String pStoredProcedureName, SqlParameter[] pParameters) throws SQLException {
        return mDatabaseUtility.executeUpdateSP(pStoredProcedureName, pParameters);
    }
    
    @Override
    public Statement executeSP(String pStoredProcedureName) throws SQLException {
        return mDatabaseUtility.executeSP(pStoredProcedureName);
    }
    
    @Override
    public Statement executeSP(String pStoredProcedureName, SqlParameter[] pParameters) throws SQLException {
        return mDatabaseUtility.executeSP(pStoredProcedureName, pParameters);
    }
    
    @Override
    public void startTransaction(IsolationLevel pIsolationLevel) throws SQLException {
        mDatabaseUtility.startTransaction(pIsolationLevel);
    }
    
    @Override
    public void commitTransaction() throws SQLException {
        mDatabaseUtility.commitTransaction();
    }
    
    @Override
    public void rollbackTransaction() throws SQLException {
        mDatabaseUtility.rollbackTransaction();
    }
    // </editor-fold>
}
